import java.sql.*;
import java.util.LinkedList;

public class DBConnection {

    public static Connection makeConnection() throws Exception{
        try {
            Class.forName( "oracle.jdbc.driver.OracleDriver" );
        } catch (ClassNotFoundException e) {
            System.out.println( "Where is your Oracle JDBC Driver?" );
            e.printStackTrace();
        }

        Connection connection = null;

        try {
            connection = DriverManager.getConnection("jdbc:oracle:thin:@secam-oracle.ex.ac.uk:2424:CSPR", "np287","mypassword");
        } catch (SQLException e) {
            System.out.println("Connection Failed! Check output console");
        }

        return connection;

    }

    public static String getQuery( String query, Connection resultConnection ) throws Exception{
        Statement statement = resultConnection.createStatement();
        ResultSet result = statement.executeQuery( query );

        String dbResult = "";

        while( result.next()){
            dbResult = result.getString(1);
        }

        return dbResult;
    }

    public static LinkedList<String> getLLQuery( String query, Connection resultConnection ) throws Exception{
        Statement statement = resultConnection.createStatement();
        ResultSet result = statement.executeQuery( query );

        LinkedList<String> dbResult = new LinkedList();

        while( result.next()){
            dbResult.add( result.getString(1) );
        }

        return dbResult;
    }

    public static LinkedList<Integer> getLLIntQuery( String query, Connection resultConnection ) throws Exception{
        Statement statement = resultConnection.createStatement();
        ResultSet result = statement.executeQuery( query );

        LinkedList<Integer> dbResult = new LinkedList();

        while( result.next()){
            dbResult.add( result.getInt(1) );
        }

        return dbResult;
    }

    public static void addQuery( String query, Connection queryConnection ) throws Exception {
        Statement statement = queryConnection.createStatement();
        ResultSet result = statement.executeQuery( query );
    }
}

